package com.blz.flare.restful;

import java.util.ResourceBundle;
import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.routing.Router;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * The primary entry point of the restful application.
 *
 * @author pchapman
 */
public class FlareRestfulApplication extends Application
	implements BeanFactoryAware
{
	private BeanFactory factory;
	private Logger logger = LoggerFactory.getLogger(FlareRestfulApplication.class);

	public FlareRestfulApplication() {
		super();
		ResourceBundle bundle = ResourceBundle.getBundle(getClass().getName().replace('.', '/'));
		setAuthor(bundle.getString("author"));
		setDescription(bundle.getString("description"));
		setName(bundle.getString("name"));
		setOwner(bundle.getString("owner"));
	}

	public FlareRestfulApplication(BeanFactory factory) {
		this();
		this.factory = factory;
	}

	public BeanFactory getBeanFactory() {
		return factory;
	}
	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		this.factory = beanFactory;
	}

	@Override
	public Restlet createInboundRoot() {
		logger.debug("Creating inbound root");
		Router router = new Router(getContext());
//		router.attach("/client/", ClientsResource.class);
//		router.attach("/client/{clientId}", ClientResource.class);
//		router.attach("/client/{clientId}/projects", ProjectsResource.class);
//		router.attach("/user/", UserResource.class);
//		router.attach("/user/{userId}", UserResource.class);
//		router.attach("/user/login/{login}", UserResource.class);
//		router.attach("/project/", ProjectsResource.class);
//		router.attach("/project/{projectId}/tasks", TasksResource.class);
//		router.attach("/task/", TaskResource.class);
		return router;
	}
}
